package com.woniu.mgr.util;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniu.mgr.common.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class WebUtil {

    public static void json(int code, String message, HttpServletResponse httpServletResponse) throws IOException {
        Result result = Result.success(200,"访问成功",null);
        result.setCode(code);
        result.setMessage(message);
        ObjectMapper objectMapper = new ObjectMapper();
        String resultJson = objectMapper.writeValueAsString(result);

        httpServletResponse.setCharacterEncoding("utf8");
        httpServletResponse.setContentType("application/json;charset=utf8");

        PrintWriter writer = httpServletResponse.getWriter();
        writer.write(resultJson);
        writer.flush();
    }
}
